package neusoft.yuejian_11.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import neusoft.yuejian_11.adapter.MatchListAdapter;
import neusoft.yuejian_11.base.BaseFragment;
import neusoft.yuejian_11.bean.MatchBean;
import neusoft.yuejian_11.listener.RetrofitListener;
import neusoft.yuejian_11.model.MatchModel;
import neusoft.yuejian_11.R;

/**
 * A simple {@link Fragment} subclass.
 */
public class MatchListFragment extends BaseFragment implements RetrofitListener {
    private RecyclerView recyclerView;
    private MatchListAdapter matchListAdapter;


    public MatchListFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view=inflater.inflate(R.layout.fragment_match_list,container,false);
        recyclerView =(RecyclerView)view.findViewById(R.id.recyclerView);

        initEvents();//点击事件处理
        initData();//网络获取
        return view;
    }

    private void initEvents() {
    }

    private void initData() {
        MatchModel matchModel = new MatchModel();
        matchModel.matchList(this);
    }

    @Override
    public void onSuccess(Object o, int flag) {
        if (getActivity() != null){
            List<MatchBean> matchBeanList = (List<MatchBean>) o;
            matchListAdapter = new MatchListAdapter(getActivity(),matchBeanList);
            LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
            layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
            recyclerView.setLayoutManager(layoutManager);
            recyclerView.setAdapter(matchListAdapter);
            recyclerView.setItemAnimator(new DefaultItemAnimator());
        }
    }

    @Override
    public void onFail() {

    }
}
